{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# week03作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一、练习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.尝试用户输入学生一周的课表信息，尝试用 占位符、2种format打印学生信息（可设计）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入周一要上的课程哦:广告文案写作\n",
      "请输入周二要上的课程哦:新媒体分析\n",
      "请输入周三要上的课程哦:APP原型制作\n",
      "请输入周四要上的课程哦:数码照片的处理\n",
      "请输入周五要上的课程哦:python语言\n",
      "周一的课:广告文案写作\n",
      "周二的课:新媒体分析\n",
      "周三的课:APP原型制作\n",
      "周四的课:数码照片的处理\n",
      "周五的课:python语言\n"
     ]
    }
   ],
   "source": [
    "# Author: Elaine\n",
    "# 占位符\n",
    "\n",
    "a=input('请输入周一要上的课程哦:')\n",
    "b=input('请输入周二要上的课程哦:')\n",
    "c=input('请输入周三要上的课程哦:')\n",
    "d=input('请输入周四要上的课程哦:')\n",
    "e=input('请输入周五要上的课程哦:')\n",
    "print('周一的课:%s'%a)\n",
    "print('周二的课:%s'%b)\n",
    "print('周三的课:%s'%c)\n",
    "print('周四的课:%s'%d)\n",
    "print('周五的课:%s'%e)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入周一的课程哦:广告文案写作\n",
      "请输入周二的课程哦:新媒体分析\n",
      "请输入周三的课程哦:APP原型制作\n",
      "请输入周四的课程哦:数码照片的处理\n",
      "请输入周五的课程哦:python语言\n",
      "周一的课:广告文案写作,\n",
      "周二的课:新媒体分析,\n",
      "周三的课:APP原型制作,\n",
      "周四的课:数码照片的处理,\n",
      "周五的课:python语言,\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 第一种format\n",
    "a=input(\"请输入周一的课程哦:\")\n",
    "b=input(\"请输入周二的课程哦:\")\n",
    "c=input(\"请输入周三的课程哦:\")\n",
    "d=input(\"请输入周四的课程哦:\")\n",
    "e=input(\"请输入周五的课程哦:\")\n",
    "course=[a,b,c,d,e]\n",
    "print(\"周一的课:{0[0]},\".format(course))\n",
    "print(\"周二的课:{0[1]},\".format(course))\n",
    "print(\"周三的课:{0[2]},\".format(course))\n",
    "print(\"周四的课:{0[3]},\".format(course))\n",
    "print(\"周五的课:{0[4]},\".format(course))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入周一的课程哦:广告文案写作\n",
      "请输入周二的课程哦:新媒体分析\n",
      "请输入周三的课程哦:APP原型制作\n",
      "请输入周四的课程哦:数码照片的处理\n",
      "请输入周五的课程哦:python语言\n",
      "周一的课：广告文案写作\n",
      "周二的课：新媒体分析\n",
      "周三的课：APP原型制作\n",
      "周四的课：数码照片的处理\n",
      "周五的课：python语言\n"
     ]
    }
   ],
   "source": [
    "# 第二种format\n",
    "\n",
    "a=input('请输入周一的课程哦:')\n",
    "b=input('请输入周二的课程哦:')\n",
    "c=input('请输入周三的课程哦:')\n",
    "d=input('请输入周四的课程哦:')\n",
    "e=input('请输入周五的课程哦:')\n",
    "print(\"周一的课：{}\".format(a))\n",
    "print(\"周二的课：{}\".format(b))\n",
    "print(\"周三的课：{}\".format(c))\n",
    "print(\"周四的课：{}\".format(d))\n",
    "print(\"周五的课：{}\".format(e))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.用户输入查询日期和时间，可返回对应的课表信息；用户查询当前时间，可返回当前课表信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入日期哦Monday\n",
      "请输入时段哦12-13\n",
      "广告文案写作\n"
     ]
    }
   ],
   "source": [
    "# 列表\n",
    "\n",
    "a=['Monday','12-13','广告文案写作']\n",
    "b=['Tuesday','3-5','新媒体分析']\n",
    "c=['Wednesday','1-2','APP原型制作']\n",
    "e=['Thusday','1-2','数码照片的处理']\n",
    "f=['Friday','3-5','python语言']\n",
    "date=input('请输入日期哦')\n",
    "time=input('请输入时段哦')\n",
    "if date ==a[0]:\n",
    "    if time==a[1]:\n",
    "        print(a[2])\n",
    "    else:\n",
    "        print('哇！没有课！')\n",
    "elif date ==b[0]:\n",
    "    if time==b[1]:\n",
    "        print(b[2])\n",
    "    elif time==b[3]:\n",
    "        print(b[4])\n",
    "    elif time==b[5]:\n",
    "        print(b[6])\n",
    "    elif time==b[7]:\n",
    "        print(b[8])\n",
    "    else:    \n",
    "        print('哇！没有课！')\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.Python内置数据结构 列表 切片、方法练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 列表的切片\n",
    "\n",
    "a=[1,2,3,4]\n",
    "a.append(5)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, '6']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.append('6')\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.count(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.index(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, '6']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.insert(0,0)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'6'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.remove(5)\n",
    "a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 3, 2, 1, 0]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.reverse()\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、思考题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.names = [.....]<br>\n",
    "2.想找出重名的名字 ------> rename = [..]？<br>\n",
    "3.循环遍历每一个元素---->[]<br>\n",
    "4.如果遍历到某一个前面出现过，存到一个[]<br>\n",
    "5.计算重名个数？<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['铠', '瑶', '后羿', '李白', '刘邦', '鲁班', '妲己', '钟馗', '韩信']\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "names=[\"铠\",'瑶','后羿','李白','刘邦','鲁班','妲己','钟馗','韩信']\n",
    "renames=[]\n",
    "no_renames=[]             \n",
    "names.count(\"铠\")\n",
    "names.count('瑶')\n",
    "names.count('后羿')            \n",
    "names.count('李白')\n",
    "names.count('刘邦')\n",
    "for a in names:                    \n",
    "    if names.count(a)>=2:           \n",
    "        renames.append(a)\n",
    "    else:\n",
    "        no_renames.append(a)\n",
    "print(no_renames)\n",
    "print(renames)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "renames_times 0 \n",
      "铠_rename_times 0\n",
      "瑶_rename_times 0\n"
     ]
    }
   ],
   "source": [
    "print('renames_times %s '%len(renames))\n",
    "print('铠_rename_times %s'%renames.count('铠'))\n",
    "print('瑶_rename_times %s'%renames.count('瑶'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "重名:['铠', '瑶']\n"
     ]
    }
   ],
   "source": [
    "names1=[\"铠\",'瑶','后羿','李白','刘邦','鲁班','妲己','铠','瑶']\n",
    "names2=names1.copy()    \n",
    "names3=set(names2)      \n",
    "for a in names3:\n",
    "    if a in names2:\n",
    "       names1.remove(a)  \n",
    "print('重名:%s'%names1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、列表训练营"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。\n",
    "2. 班上投票竞选，将选择票数最高的同学担任班长，请你设计一个投票系统，输入名字即可投票，最后统计大家的得票数，公开投票结果，并宣布谁担任班长。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一行字符串哦:abc123\n",
      "letter:3个\n",
      "number:3个\n",
      "white_space:0个\n",
      "other:0个\n"
     ]
    }
   ],
   "source": [
    "a=input(\"请输入一行字符串哦:\")\n",
    "letter=[]\n",
    "number=[]\n",
    "white_space=[]\n",
    "other=[]\n",
    "for b in a:\n",
    "    if b>='a' and b<='z' or b>='A' and b<='Z':\n",
    "        letter.append(b)\n",
    "    elif b in '0123456789':\n",
    "        number.append(b)\n",
    "    elif b==' ':\n",
    "        white_space.append(b)\n",
    "    else:\n",
    "        other.append(b)\n",
    "c=len(letter)\n",
    "d=len(number)\n",
    "e=len(white_space)\n",
    "f=len(other)\n",
    "print('letter:%s个'%c)\n",
    "print('number:%s个'%d)\n",
    "print('white_space:%s个'%e)\n",
    "print('other:%s个'%f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你心目中的班长:韩信\n",
      "你心目中的班长:韩信\n",
      "你心目中的班长:韩信\n",
      "你心目中的班长:韩信\n",
      "你心目中的班长:韩信\n",
      "恭喜韩信成为班长啦!撒花！！\n"
     ]
    }
   ],
   "source": [
    "student={'韩信':0,'李白':0,'后羿':0,'钟馗':0,'妲己':0}\n",
    "count=0\n",
    "while count<5:\n",
    "    name=input(\"你心目中的班长:\")\n",
    "    if name=='韩信':\n",
    "       student['韩信']+=1\n",
    "    elif name=='李白':\n",
    "       student['李白']+=1\n",
    "    elif name=='后羿':\n",
    "       student['后羿']+=1\n",
    "    elif name=='钟馗':\n",
    "       student['钟馗']+=1\n",
    "    else:\n",
    "       student['妲己']+=1\n",
    "    count+=1\n",
    "\n",
    "max(student.values())\n",
    "for key,value in student.items():\n",
    "    if(value == max(student.values())):\n",
    "        print('恭喜%s成为班长啦!撒花！！'%key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
